package com.wsc.wisdomchinaqinghe.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wsc.wisdomchinaqinghe.R;
import com.wsc.wisdomchinaqinghe.javaBean.FloorInfoListBean;

import java.util.List;

/**
 * 楼宇信息适配器
 * Created by ${wangtao} on 2017/3/2.
 */

public class FloorInoAdapter extends BaseAdapter {
    private Context context;
    private List<FloorInfoListBean> messageBeen;

    public FloorInoAdapter(Context context, List<FloorInfoListBean> messageBeen) {
        this.context = context;
        this.messageBeen = messageBeen;
    }

    @Override
    public int getCount() {
        return messageBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return messageBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        View view = convertView;
        if (view == null) {
            view= LayoutInflater.from(context).inflate(R.layout.item_floorinfo,null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        String guideImage=messageBeen.get(position).getGuideImg();
        if(guideImage==null || guideImage.isEmpty())
        {
            holder.item_jdts_image.setVisibility(View.GONE);
        }else {
            holder.item_jdts_image.setVisibility(View.VISIBLE);
            Glide.with(context).load(guideImage).into(holder.item_jdts_image);
        }

        holder.item_jdts_title.setText(messageBeen.get(position).getBuildingName());
        holder.item_jdts_content.setText(messageBeen.get(position).getAddr());
        holder.item_jdts_address.setText(messageBeen.get(position).getPhone());

        return view;
    }

    public class ViewHolder {

        private ImageView item_jdts_image;//图片
        private TextView item_jdts_title;//标题
        private TextView item_jdts_content;//内容
        private TextView item_jdts_address;//地址

        public ViewHolder(View view) {
            item_jdts_image = (ImageView) view.findViewById(R.id.item_jdts_image);
            item_jdts_title = (TextView) view.findViewById(R.id.item_jdts_title);
            item_jdts_content = (TextView) view.findViewById(R.id.item_jdts_content);
            item_jdts_address = (TextView) view.findViewById(R.id.item_jdts_address);
        }
    }
}
